import Vue from 'vue'
import VueRouter from 'vue-router'
const requireComponent = require.context('@/examples/docs',false,/.md$/)
let res_cpt = {}
requireComponent.keys().forEach(fileName => {
  const scp = requireComponent(fileName)
  res_cpt[fileName.replace(/^\.\/(.*)\.\w+$/, '$1')] = scp.default
})
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    redirect:'/introduce',
    meta: { title: '表格打印', icon: 'home' },
    // component: () => import('../views/home.vue')
  },
  {
    path: '/introduce',
    name: 'introduce',
    component:r => require.ensure([], () => r(require('../docs/introduce.md')))
  },
  {
    path: '/icon',
    name: 'icon',
    meta: { title: '字体图标', icon: 'icon' },
    component: () => import('../docs/icon.md')
  },
  {
    path: '/tab',
    name: 'tab',
    component:r => require.ensure([], () => r(require('../docs/tabs.md')))
  },
  {
    path: '/checkbox',
    name: 'checkbox',
    component:r => require.ensure([], () => r(require('../docs/checkbox.md')))
  },
  {
    path: '/sideFoldPop',
    name: 'sideFoldPop',
    meta: { title: '抽屉', icon: 'icon' },
    component: () => import('../docs/sideFoldPop.md')
  },
  {
    path: '/button',
    name: 'button',
    meta: { title: '抽屉', icon: 'icon' },
    component: () => import('../docs/button.md')
  },
  {
    path: '/layout',
    name: 'layout',
    component:r => require.ensure([], () => r(require('../docs/layout.md')))
  },
  {
    path: '/svgIcon',
    name: 'svgIcon',
    component:r => require.ensure([], () => r(require('../docs/svgIcon.md')))
  },
  {
    path: '/menu',
    name: 'menu',
    component:r => require.ensure([], () => r(require('../docs/menu.md')))
  },
  {
    path: '/dropdown',
    name: 'dropdown',
    component:r => require.ensure([], () => r(require('../docs/dropdown.md')))
  },
  {
    path: '/input',
    name: 'input',
    component:r => require.ensure([], () => r(require('../docs/input.md')))
  },
  {
    path: '/radio',
    name: 'radio',
    component:r => require.ensure([], () => r(require('../docs/radio.md')))
  },
  {
    path: '/popover',
    name: 'popover',
    component:r => require.ensure([], () => r(require('../docs/popover.md')))
  },
  {
    path: '/debounce',
    name: 'debounce',
    component:r => require.ensure([], () => r(require('../docs/debounce.md')))
  },
  {
    path: '/colorPiker',
    name: 'colorPiker',
    component:r => require.ensure([], () => r(require('../docs/colorPiker.md')))
  },
  {
    path: '/mask',
    name: 'mask',
    component:r => require.ensure([], () => r(require('../docs/mask.md')))
  },
  {
    path: '/messageBox',
    name: 'messageBox',
    component:r => require.ensure([], () => r(require('../docs/messageBox.md')))
  },
  {
    path: '/map',
    name: 'map',
    component:r => require.ensure([], () => r(require('../docs/map.vue')))
  }
]

//解决路由报错
const originalPush = VueRouter.prototype.push
  VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
  routes
})

export default router
